#include "myscene.h"
#include<stdlib.h>

myscene::myscene(QObject *parent)
    : QGraphicsScene(parent)
{  
        this->item[0]=new myitem;
        this->item[0]->setPos(0*this->item[0]->boundingRect().width(),0*this->item[0]->boundingRect().height());
        this->addItem(this->item[0]);
        this->item[1]=new myitem;
        this->item[1]->setPos(1*this->item[1]->boundingRect().width(),0*this->item[1]->boundingRect().height());
        this->addItem(this->item[1]);
        this->item[2]=new myitem;
        this->item[2]->setPos(2*this->item[2]->boundingRect().width(),0*this->item[2]->boundingRect().height());
        this->addItem(this->item[2]);
        this->item[3]=new myitem;
        this->item[3]->setPos(0*this->item[3]->boundingRect().width(),1*this->item[3]->boundingRect().height());
        this->addItem(this->item[3]);
        this->item[4]=new myitem;
        this->item[4]->setPos(0*this->item[4]->boundingRect().width(),2*this->item[4]->boundingRect().height());
        this->addItem(this->item[4]);
        this->item[5]=new myitem;
        this->item[5]->setPos(1*this->item[5]->boundingRect().width(),1*this->item[5]->boundingRect().height());
        this->addItem(this->item[5]);
        this->item[6]=new myitem;
        this->item[6]->setPos(1*this->item[6]->boundingRect().width(),2*this->item[6]->boundingRect().height());
        this->addItem(this->item[6]);
        this->item[7]=new myitem;
        this->item[7]->setPos(2*this->item[7]->boundingRect().width(),1*this->item[7]->boundingRect().height());
        this->addItem(this->item[7]);
        this->item[8]=new myitem;
        this->item[8]->setPos(2*this->item[8]->boundingRect().width(),2*this->item[8]->boundingRect().height());
        this->addItem(this->item[8]);
        this->ptime=new QTimer;
        connect(this->ptime,SIGNAL(timeout()),this,SLOT(showmice()));
        this->ptime->start(1000);
}
void myscene::showmice(){
    int count=rand()%2+1;
    for(int i=0;i<9;i++){
        this->item[i]->setPic(":/Images/Img/hole.png");
    }
    for(int i=0;i<count;i++){
        int j=rand()%9;
        this->item[j]->setPic(":/Images/Img/mice1.png");
    }
}
